<?php 
	/**
	 * 主程序，每日抓取最新数据，并提取和入库
	 */
	header("Content-Type:text/html;charset=utf-8");
	include_once dirname(dirname(__FILE__))."/include/common.inc.php";
	include_once dirname(dirname(__FILE__))."/youyuan/function.youyuan.php";
	$global_site = "youyuan";
	/*
	$log = file_get_contents('data.log');
	if($log ==1){
		echo 'running';
		exit;
	}
	*/
	//抓取日期，默认为昨天
	$ymd =  date("Y-m-d", time()-60*60*24);
	if ($argc > 1) {
		$ymd = date("Y-m-d", strtotime($argv[1]));
	}
	
	//是否删除数据库中已经存在的数据
	if($argc > 2 && $argv[2] == "DELETE"){
		global $conn;
		$tblName = getTblname($ymd);
		$sql = "delete from $tblName where `from`='youyuan' and fetch_date='$ymd' ";
		$conn->query($sql);
	}
	$page = file_get_contents('117125404.html');
	$page = str_replace(array(" ","\t","\n","\r","&nbsp;"), "", $page);
	doWithYouyuanPage(117125404,$ymd,$page);
	//file_put_contents('aaa.txt', $page);
	exit;
?>